# netpbm
# Builds from https://github.com/puppylinux-woof-CE/petbuilds

. ../func
. ../build.conf

#VER=10.35.97
#VER=10.49.02
#VER=10.47.62
VER=10.66.02
#URL=http://downloads.sourceforge.net/project/netpbm/super_stable/${VER}
URL=https://mirror.aarnet.edu.au/pub/slackware/slackware64-14.2/source/l/netpbm
#URL=http://distro.ibiblio.org/puppylinux/sources/n
PKG=netpbm
#COMP=tgz
COMP=tar.xz
DESC="a comprehensive suite of image manipulaton tools"
DEPS=+libjpeg,+libpng
CAT=BuildingBlock
DESKTOP=netpbm.desktop
BUILD=
CWD=$(pwd)
[ -z "$MWD" ] && MWD=$(dirname $CWD)	
[ -z "$BUILD" ] && BUILD=$DEF_BUILD
[ -f "$DESKTOP" ] || DESKTOP=not
[ -z "$DEPS" ] && DEPS=not	

ARCH=$(uname -m)
case $ARCH in
 *64) 	LIBDIR=$LIBCONF64 ;;
 arm*)	LIBDIR=$LIBCONFarm;;
 *) 	LIBDIR=$LIBCONF32 ;;
esac

patch_me() {
	for i in *patch;do
		echo "applying $i"
		(cd ${PKG}-${VER}; patch -p1 < ../$i) || exit 1
	done
}

build() {
	cd ${PKG}-${VER}
	if [ "$ARCH" = "x86_64" ]; then
	  cat $CWD/config.mk \
	    | sed -e '/^CFLAGS/s/^CFLAGS = .*/& -fPIC/' -e 's%/usr/lib%/usr/lib64%g' > config.mk #Makefile.config
	else
	  cat $CWD/config.mk > config.mk #Makefile.config
	fi
	#./configure 
	make
	[ "$?" -eq 0 ] || exit
	make package pkgdir=$CWD/${PKG}-install
	# FIX path .. directly from SlackBuild, Patrick J. Volkerding, Sebeka, MN, USA
	( cd $CWD/${PKG}-install
	  rm README
	  mkdir -p usr
	  mv * usr 2>/dev/null
	  cd usr
	  mkdir -p share/doc/netpbm-$VERSION
	  mv man share/
	  mv VERSION bin/doc.url share/doc/netpbm-$VERSION
	  ( cd lib ; ln -sf libnetpbm.so.11 libnetpbm.so )
	  mv lib ${LIBDIR}
	  rm -rf *config_template link misc pkginfo man/man1/manweb.1 man/web
	)
	cd -
}
	
# main
retrieve ${PKG}-${VER}.${COMP}
extract ${PKG}-${VER}.${COMP}
patch_me
build
package_std $PKG $VER $ARCH $DESKTOP "$DESC" $DEPS $CAT	
